const autoPlay = (chart, size, timer, tips = true, milliseconds = 2500) => {
  let index = -1
  // 销毁timer
  // 自动播放chart
  chart.on('mouseover', (e) => {
    e.dataIndex !== index &&
      chart.dispatchAction({
        type: 'downplay',
        seriesIndex: 0,
        dataIndex: index,
      })
  })
  timer.value = setInterval(() => {
    chart.dispatchAction({
      type: 'downplay',
      seriesIndex: 0,
      dataIndex: index,
    })

    index = (index + 1) % size

    chart.dispatchAction({
      type: 'highlight',
      seriesIndex: 0,
      dataIndex: index,
    })
    tips &&
      chart.dispatchAction({
        type: 'showTip',
        seriesIndex: 0,
        dataIndex: index,
      })
  }, milliseconds)
}

export { autoPlay }
